package com.heima.admin.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.admin.service.WmUserService;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmUserDto;
import com.heima.model.wemedia.pojos.WmUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/vmuser")
public class WmUserController {

    @Autowired
    private WmUserService wmUserService ;


    /**
     * 增加自媒体人
     * @param wmUser
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmUser wmUser){
       wmUserService.save(wmUser);
       return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);

    }


    @GetMapping("findbyname/{name}")
    public WmUser findByName(@PathVariable("name") String name){
        LambdaQueryWrapper<WmUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(WmUser::getName,name);
        List<WmUser> list = wmUserService.list(lambdaQueryWrapper);

        if(list == null && list.isEmpty()){
            return null;
        }
        WmUser wmUser = list.get(0);
        return wmUser;
    }

}
